package com.thinkingcoder.tcrpc.demo.provider;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Import;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.thinkingcoder.tcconfig.client.annotation.EnableTcConfig;
import com.thinkingcoder.tcrpc.core.api.RpcResponse;
import com.thinkingcoder.tcrpc.core.config.ProviderConfig;
import com.thinkingcoder.tcrpc.demo.api.IUserService;

@RestController
@SpringBootApplication
// @EnableApolloConfig
@Import({ProviderConfig.class})
@EnableTcConfig
public class TcrpcDemoProviderApplication {

    // @Bean
    // ApolloChangedListener apolloChangedListener() {
    // return new ApolloChangedListener();
    // }

    public static void main(String[] args) {
        SpringApplication.run(TcrpcDemoProviderApplication.class, args);
    }

    @Autowired
    IUserService userService;

    @RequestMapping("/ports")
    public RpcResponse<String> ports(@RequestParam("ports") String ports) {
        userService.setTimeoutPorts(ports);
        RpcResponse<String> response = new RpcResponse<>();
        response.setStatus(true);
        response.setData("OK:" + ports);
        return response;
    }

    // @Value("${tcrpc.provider.test}")
    // String test;
    //
    // @Autowired
    // ProviderProperties providerProperties;
    //
    // @RequestMapping("/test")
    // public String test() {
    // return test + "_" + providerProperties.getTest();
    // }
}
